package com.api.shopapi.service.impl;

import com.api.shopapi.entity.NursingItem;
import com.api.shopapi.entity.dto.NursingItemDTO;
import com.api.shopapi.mapper.NursingItemMapper;
import com.api.shopapi.service.NursingItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("NursingItemServiceImplOne")
public class NursingItemServiceImpl  implements NursingItemService {

    @Autowired
    private NursingItemMapper nursingItemMapper;


    @Override
    public int insert(NursingItem nursingItem) {
        return nursingItemMapper.insert(nursingItem);
    }

    @Override
    public int update(NursingItem nursingItem) {
        return nursingItemMapper.update(nursingItem);
    }

    @Override
    public int delete(String nursingItemCode) {
        return nursingItemMapper.delete(nursingItemCode);
    }

    @Override
    public PageInfo<NursingItemDTO> getPageList(int pageIndex, int pageSize, String institutionCode, String name, int status, String nursingTypeCode) {
        PageHelper.startPage(pageIndex, pageSize);
        List<NursingItemDTO> nursingItems = nursingItemMapper.getListByInstitutionCode(institutionCode,name,status,nursingTypeCode);
        PageInfo<NursingItemDTO> pageInfo = new PageInfo<>(nursingItems);
        return pageInfo;
    }


    @Override
    public NursingItem getByNursingItemCode(String nursingItemCode) {
        return nursingItemMapper.getByNursingItemCode(nursingItemCode);
    }

    @Override
    public NursingItem getByNameAndInstitutionCode(String name, String institutionCode) {
        return nursingItemMapper.getByNameAndInstitutionCode(name,institutionCode);
    }

    @Override
    public List<NursingItem> getList(String institutionCode) {
        return nursingItemMapper.getList(institutionCode);
    }

    @Override
    public List<NursingItem> getListByNursingType(String institutionCode,String nursingTypeCode) {
        return nursingItemMapper.getListByNursingType(institutionCode,nursingTypeCode);
    }

    @Override
    public
    PageInfo<NursingItem> pageByGovCode(int pageIndex, int pageSize, String governmentCode){
        PageHelper.startPage(pageIndex, pageSize);
        List<NursingItem> nursingItems = nursingItemMapper.listByGovCode(governmentCode);
        PageInfo<NursingItem> pageInfo = new PageInfo<>(nursingItems);
        return pageInfo;
    }


}
